import axios from "axios";
import nProgress from "nprogress";
import 'nprogress/nprogress.css'
import store from "@/store";
const request = axios.create({
  // 基础路径
  baseURL: process.env.VUE_APP_API,
  // 最迟响应时间
  timeout: 10000
})
//请求拦截器
request.interceptors.request.use(
  (config) => {
    nProgress.start()
    const userTempId = store.state.user.userTempId
    config.headers.userTempId = userTempId
    //每次发送请求的时候,在header中携带token
    const token = store.state.user.token;
    config.headers.token = token;
    return config
  },
  (error) => {
    nProgress.done()
    return Promise.reject(error)
  }
)
// 响应拦截器
request.interceptors.response.use(
  (response) => {
    nProgress.done()
    return response.data.data
  }, (error) => {
    nProgress.done()
    return Promise.reject(error)
  })
export default request